import React from 'react'
import LifeBannerBg from '../../../../components/lift_components/LifeBannerBg'
import LifeText from '../../../../components/lift_components/LifeText'
import CleanService from '../../../../components/lift_components/CleanService'
import bg04 from '../../../../static/images/life_img/bg_04.png'
import { getdaycleanData } from '../../../../fetch/lifeService'
import CleanBtn from '../../../../components/lift_components/CleanBtn'

import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { bindActionCreators } from "redux"
import * as cleanActions from '../../../../redux/actions/life/clean'


class DailyCleaning extends React.Component {
  constructor(){
    super();
    this.state = {
      data:{
        servicePrice:[],
        timer:[]
      },
      isLogin:true
    }
  }
  componentDidMount(){
    getdaycleanData()
    .then(res => {
      this.setState({
        data:res
      })
    })
  }
  reservate(value){
    console.log(value);
    //进行用户是否登录判断
    //假设已经登录
    const userid = '2434453'
    if(this.state.isLogin){
      //储存数据
      this.props.cleanActions.add({
        userid:userid,
        value:value
      })
    }else {
      console.log('去登陆');
    }
  }
  render() {
    return(
      <div>
        <LifeBannerBg imgUrl={ bg04 } />
        {
          this.state.data
          ?(
            <div>
              <LifeText lifeTitle='专业除螨' lifeText={ this.state.data.context }/>
              <CleanService data={this.state.data }/>
            </div>
          )
          :<div>数据正在加载中...</div>
        }
        <CleanBtn reservate={this.reservate.bind(this)}/>
      </div>
    )
  }
}


//......................redux....................

//读
function mapStateToProps(state){
  return{
    clean:state.clean,
  }
}

//写
function mapDispatchToProps(dispatch){
  return{
    cleanActions:bindActionCreators(cleanActions,dispatch)
  }
}

export default withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(DailyCleaning))
